// 风控模块相关API
import request from '@/utils/http'
import type { BaseResult, PageResult } from '@/types/axios'
import type {
  RiskBlack,
  RiskBlackPageParam,
  RiskBlackSaveParam,
  RiskBlackUpdateParam,
  RiskBlackDeleteParam,
  RiskUserBlack,
  RiskRule,
  RiskRulePageParam,
  RiskRuleSaveParam,
  RiskRuleUpdateParam,
  RiskRuleDeleteParam,
  UserSearchParam,
  CereBuyerUser
} from './model/riskModel'

// ===== 黑名单管理相关API =====

/**
 * 查询IP黑名单列表
 */
export function getAllIpBlackList(
  data: RiskBlackPageParam
): Promise<BaseResult<PageResult<RiskBlack>>> {
  return request.post({
    url: '/risk/getAllIpBlackList',
    data
  })
}

/**
 * 查询用户黑名单列表
 */
export function getAllUserBlackList(
  data: RiskBlackPageParam
): Promise<BaseResult<PageResult<RiskUserBlack>>> {
  return request.post({
    url: '/risk/getAllUserBlackList',
    data
  })
}

/**
 * 新增IP或用户黑名单
 */
export function saveRiskBlack(data: RiskBlackSaveParam): Promise<BaseResult<number>> {
  return request.post({
    url: '/risk/saveRiskBlack',
    data
  })
}

/**
 * 更新IP或用户黑名单
 */
export function updateRiskBlack(data: RiskBlackUpdateParam): Promise<BaseResult<number>> {
  return request.post({
    url: '/risk/updateRiskBlack',
    data
  })
}

/**
 * 删除IP或用户黑名单
 */
export function deleteRiskBlack(data: RiskBlackDeleteParam): Promise<BaseResult<number>> {
  return request.post({
    url: '/risk/deleteRiskBlack',
    data
  })
}

// ===== 规则管理相关API =====

/**
 * 查询规则列表
 */
export function getAllRiskRule(data: RiskRulePageParam): Promise<BaseResult<PageResult<RiskRule>>> {
  return request.post({
    url: '/risk/getAllRiskRule',
    data
  })
}

/**
 * 新增规则配置
 */
export function saveRiskRule(data: RiskRuleSaveParam): Promise<BaseResult<number>> {
  return request.post({
    url: '/risk/saveRiskRule',
    data
  })
}

/**
 * 更新规则配置
 */
export function updateRiskRule(data: RiskRuleUpdateParam): Promise<BaseResult<number>> {
  return request.post({
    url: '/risk/updateRiskRule',
    data
  })
}

/**
 * 删除规则配置
 */
export function deleteRiskRule(data: RiskRuleDeleteParam): Promise<BaseResult<number>> {
  return request.post({
    url: '/risk/deleteRiskRule',
    data
  })
}

/**
 * 获取规则详情
 */
export function getRiskRuleDetail(data: { id: string }): Promise<BaseResult<RiskRule>> {
  return request.post({
    url: '/risk/getRiskRuleDetail',
    data
  })
}

/**
 * 获取黑名单详情
 */
export function getRiskBlackDetail(data: { id: number }): Promise<BaseResult<RiskBlack>> {
  return request.post({
    url: '/risk/getRiskBlackDetail',
    data
  })
}

/**
 * 搜索用户信息
 */
export function searchUser(data: UserSearchParam): Promise<BaseResult<PageResult<CereBuyerUser>>> {
  return request.post({
    url: '/buyer/searchUser',
    data
  })
}
